<div class="modal-header">
   <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
   <span class="modal-title">个人设置</span>
   </div>
   <form  method="post" id="profileForm">
   <div class="modal-body">
        
                    <div class="form-group form-inline col-md-12">
                    <label >姓名：</label>
                    ${user?.name}
                    </div>
                     <div class="form-group form-inline col-md-12">
                     #{f.password 'oldPassword',required:'true',label:'旧密码' /}
                    
                    </div>
                    <div class="form-group form-inline col-md-12">
                    #{f.password 'newPassword',required:'true',label:'新密码' /}
                    </div>
                   <div class="form-group form-inline col-md-12">
                    #{f.password 'confirmPassword',required:'true',label:'确认密码' /}
                    </div>

            
  
   </div>
   </form>
  <div class="modal-footer col-lg-12">
            <button type="button" class="btn btn-primary" onclick="save();">保存</button>
            <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
 
 </div> 
<script type="text/javascript">
  function save(){
	 var rcode = checkValid();
	 var _old = $('input[name="oldPassword"]');
	 if(rcode){
		  var params = $("#profileForm").serializeArray();
		  $.post('/user/${user?.id}/profile',params,function(data){
			 if(data){
				 if(0==data.rcode){
					 tipInfo({"title":'修改成功!',type:'success'},hide);
				 }else if(1==data.rcode){
					 _old.siblings(".error-msg").text("旧密码错误"); 
				 }else{
					 _old.siblings(".error-msg").text("未知错误，请重新登录");
				 }
			 }
           
        }); 
	 }			
	 return;
  }
  
  function hide(){
	  $('#mainDialog').modal('hide');
  }
  
  function checkValid(){
	  var rcode = true;
	  var _old = $('input[name="oldPassword"]');
	  var _new = $('input[name="newPassword"]');
	  var _confirm = $('input[name="confirmPassword"]');
	  var _oldVal = $.trim(_old.val());
	  var _newVal = $.trim(_new.val());
	  var _confirmVal = $.trim(_confirm.val());
	  
	  if(!_oldVal){
		  _old.siblings(".error-msg").text("旧密码不能为空");
		  rcode = false;
	  }else{
		  _old.siblings(".error-msg").text(""); 
	  }
	
	  if(!_newVal){
		  _new.siblings(".error-msg").text("新密码不能为空");
		  rcode = false
	  }else{
		  _new.siblings(".error-msg").text(""); 
	  }
	  if(!_confirmVal){
		  _confirm.siblings(".error-msg").text("确认密码不能为空");
		  rcode = false;
	  }else if(_newVal!=_confirmVal){
		  _confirm.siblings(".error-msg").text("新密码前后不一致"); 
		  rcode = false;
	  }else{
		  _confirm.siblings(".error-msg").text("");
	  }
	 return rcode;
	  
  }
</script>